package com.jd.tuning.jvm.async;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * async异步化
 */
@Component
public class AsyncDemoAsyncAnnotation {

  @Autowired
  public AsyncJob asyncJob;

  private  void subBiz1() throws InterruptedException {
    Thread.sleep(1000L);
    System.out.println(new Date()+"subBiz1");
  }

  private  void subBiz2() throws InterruptedException {
    Thread.sleep(1000L);
    System.out.println(new Date()+"subBiz2");
  }



  public void biz() throws InterruptedException{
      this.subBiz1();
      asyncJob.saveOpLog();
      this.subBiz2();
  }
  public void biz2() throws InterruptedException, ExecutionException {
    this.subBiz1();
    Future<String> future= asyncJob.saveOpLogStr();
    this.subBiz2();
    String result=future.get();
  }

}

